/**
 * @Author:  renyc
 * @Date: 2022年12月20日23:27:28
 */

import * as Cesium from "cesium/Cesium";
import Util from "../../utils/Util";
import PrimitiveOverlay from "./PrimitiveOverlay";

class RectanglePrimitive extends PrimitiveOverlay{

    constructor(envelope, options){
        super();
        this._envelope = envelope;
        this._options = options;
        this._delegate = undefined;

        if(this._envelope){
            this._delegate = this._createPrimivive();
        }
    }

    _createPrimivive(){
        let envelope = this._envelope;
        //1. 创建几何对象实例
        let instance = new Cesium.GeometryInstance({
          id: this._id,          
          // 创建一个Rectangle类型的Geometry
          geometry: new Cesium.RectangleGeometry({
            // 定义Rectangle的空间范围
            //rectangle: Cesium.Rectangle.fromDegrees(116, 39, 120, 45),
            rectangle: Cesium.Rectangle.fromDegrees(envelope.xmin, envelope.ymin, envelope.xmax, envelope.ymax),
            // 定义Rectangle的VertexFormat
            vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEXT_FORMAT,
          }),
        });
        instance.delegate = this._delegate;

          //2. 创建Apperance实例
        let appearance = new Cesium.EllipsoidSurfaceAppearance({
          material: Cesium.Material.fromType("Stripe"),
        });

        let primitive = new Cesium.Primitive({
          // 利用新创建的instance为Primitive的geometryInstance属性赋值
          geometryInstances: instance,
          // 定义instance的apperance
          appearance: appearance,
        });

        return primitive;
  
        //   //3. 将几何对象添加到Cesium的Scene上
        //   let obj = viewer.scene.primitives.add(
        //     new Cesium.Primitive({
        //       // 利用新创建的instance为Primitive的geometryInstance属性赋值
        //       geometryInstances: instance,
        //       // 定义instance的apperance
        //       appearance: appearance,
        //     })
        //   );

    }
}

export default RectanglePrimitive